﻿using Model;
using System;
using System.Data;

namespace BLL
{
    public class Sys_FavoriteBLL : BaseBLL
    {
        public DataTable GetDataAll(decimal operId)
        {
            string sql = string.Format(@"select * from sys_favorite where n_user_id=" + operId);
            DataTable dt = Query(sql);
            return dt;
        }

        public bool INSERT(Sys_Favorite model, string operName, decimal operId)
        {
            //获取序列
            model.N_FAVORITE_ID = GetSequence("SEQ_Sys_RoleGroup");
            string sql = string.Format(@"insert into sys_favorite
  (n_favorite_id, c_favorite_name, c_favorite_url, d_favorite_date, n_user_id)
values
  ({0}, '{1}', '{2}',sysdate,{3})", model.N_FAVORITE_ID, model.C_FAVORITE_NAME, model.C_FAVORITE_URL, operId);

            int count = NoQuery(sql, operName);
            if (count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool DELETE(string fId, string operName, decimal operId)
        {
            string sql = string.Format(@"delete sys_favorite
 where n_favorite_id = {0} and n_user_id={1}", fId, operId);

            int count = NoQuery(sql, operName);
            if (count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public Sys_Favorite GetUrlgetTable(string url, string operName, decimal operId)
        {
            string sql = string.Format(@"select n_favorite_id,
       c_favorite_name,
       c_favorite_url,
       d_favorite_date,
       n_user_id,
       sysm.module_id
  from sys_favorite sysf
  left outer join sys_module sysm
    on sysm.module_path = sysf.c_favorite_url
where c_favorite_url='{0}' and n_user_id={1}", url, operId);
            DataTable dt = Query(sql, operName);
            Sys_Favorite model = new Sys_Favorite();
            model.N_FAVORITE_ID = Convert.ToDecimal(dt.Rows[0]["N_FAVORITE_ID"]);
            model.N_USER_ID = Convert.ToDecimal(dt.Rows[0]["N_USER_ID"]);
            model.C_FAVORITE_NAME = dt.Rows[0]["C_FAVORITE_NAME"].ToString();
            model.C_FAVORITE_URL = dt.Rows[0]["C_FAVORITE_URL"].ToString();
            model.D_FAVORITE_DATE = Convert.ToDateTime(dt.Rows[0]["D_FAVORITE_DATE"].ToString());
            Sys_Module smod = new Sys_Module();
            smod.MODULE_ID = Convert.ToDecimal(dt.Rows[0]["MODULE_ID"]);
            return model;
        }

        /// <summary>
        /// 根据路径得到模块信息
        /// </summary>
        /// <param name="url"></param>
        /// <param name="operName"></param>
        /// <param name="operId"></param>
        /// <returns></returns>
        public DataTable GetUrlgetTable1(string url, string operName, decimal operId)
        {
            string sql = string.Format(@"select n_favorite_id,
       c_favorite_name,
       c_favorite_url,
       d_favorite_date,
       n_user_id,
       sysm.module_id
  from sys_favorite sysf
  left outer join sys_module sysm
    on sysm.module_path = sysf.c_favorite_url
where c_favorite_url='{0}' and n_user_id={1}", url, operId);
            DataTable dt = Query(sql, operName);
            return dt;
        }

        public DataTable GetModuleByAll(string win, decimal logonID)
        {
            string sql = @"select n_favorite_id AS D0,
       c_favorite_name AS D1,
       c_favorite_url AS D2,
       d_favorite_date AS D3,
       n_user_id AS D4,
       '' AS D5,
       0 AS D6
  from sys_favorite
 WHERE n_User_Id = " + logonID;

            DataTable dt = Query(sql);

            return dt;
        }
    }
}